package com.kesh.ltank.screens;

import java.util.List;

import com.android.framework.Game;
import com.android.framework.Graphics;
import com.android.framework.Input.TouchEvent;
import com.android.framework.Screen;
import com.kesh.ltank.game.GlobalVars.GameImages;
import com.kesh.ltank.game.GlobalVars.ScreenImages;
import com.kesh.ltank.game.Utils;

public class MainMenuScreen extends Screen {
	
	public boolean ngamePressed = false;
	public boolean lselectPressed = false;
	public boolean resumePressed = false;
	public boolean optionsPressed = false;
	public boolean helpPressed = false;
	public boolean quitPressed = false;
	
	
	public MainMenuScreen(Game game) {
		super(game);
	}

	@Override
	public void update(float deltaTime) {

		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();

		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_DOWN) {
				if (Utils.inBounds(event, 8, 160, 121, 121)) {
					ngamePressed = true;
				} else if (Utils.inBounds(event, 78, 290, 121, 121)) {
					lselectPressed = true;
				} else if (Utils.inBounds(event, 213, 209, 121, 121)) {
					resumePressed = true;
				} else if (Utils.inBounds(event, 144, 410, 121, 121)) {
					optionsPressed = true;
				} else if (Utils.inBounds(event, 354, 316, 121, 121)) {
					helpPressed = true;
				} else if (Utils.inBounds(event, 283, 452, 121, 121)) {
					quitPressed = true;
				}
			} else if (event.type == TouchEvent.TOUCH_UP) {
				if (ngamePressed) {
					ngamePressed = false;
				}
				if (lselectPressed) {
					lselectPressed = false;
				}
				if (resumePressed) {
					resumePressed = false;
					game.setScreen(new GameScreen(game));
				}
				if (optionsPressed) {
					optionsPressed = false;
				}
				if (helpPressed) {
					helpPressed = false;
				}
				if (quitPressed) {
					quitPressed = false;
					backButton();
				}
			}
		}
	}

	@Override
	public void paint(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawImage(ScreenImages.Menu.image, 0, 0);
		if(ngamePressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 8,160);
		else 
			g.drawImage(GameImages.Bubble.image, 8,160);
		
		if(lselectPressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 78,290);
		else 
			g.drawImage(GameImages.Bubble.image, 78, 290);
		
		if(resumePressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 213,209);
		else 
			g.drawImage(GameImages.Bubble.image, 213,209);
		
		if(optionsPressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 144,410);
		else 
			g.drawImage(GameImages.Bubble.image, 144,410);
		
		if(helpPressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 354,316);
		else 
			g.drawImage(GameImages.Bubble.image, 354,316);
		
		if(quitPressed)
			g.drawImage(GameImages.Bubble_Pressed.image, 283,452);
		else 
			g.drawImage(GameImages.Bubble.image, 283,452);
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {

	}

	@Override
	public void backButton() {
		android.os.Process.killProcess(android.os.Process.myPid());
	}
}
